using System;
using System.Data;
using System.Configuration;

namespace eShop.Utility
{
    public class ConnectionStringManager
    {
        public static string DefaultDBConnectionString
        {
            get
            {
                // Reading the currently connection string selection from web.config
                string currentConnectionStringName = ConfigurationManager.AppSettings["CurrentDatabase"];

                if (!string.IsNullOrEmpty(currentConnectionStringName))
                {
                    // We found the current selection, so find the connection string
                    // with that name
                    ConnectionStringSettings currentConnectionString = 
                        ConfigurationManager.ConnectionStrings[currentConnectionStringName];

                    // If we can find the connection string then we return it
                    if (currentConnectionString != null)
                        return currentConnectionString.ConnectionString;
                }
                // If we have failed to return the connection, return null
                return null;
            }
        }
    }
}

